﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject.Core;
using Hotnet.Dal.NSDalCommon;
using Hotnet.Entity;
using Hotnet.Entity.Enum;
using Hotnet.Biz.NSBizPicture;
using Hotnet.Biz.NSBizVideo;
using Hotnet.Biz.Properties;

namespace Hotnet.Biz.NSBizCommon
{
	public class BizBigEye : BaseBiz<BigEye>
	{
		public static DalBigEye dalBigEye = new DalBigEye();
		private BizPicture bizPicture;
		private BizPicture BizPicture
		{
			get
			{
				if (bizPicture == null)
					bizPicture = new BizPicture();
				return bizPicture;
			}
		}

		private BizPictureGroup bizPictureGroup;
		private BizPictureGroup BizPictureGroup
		{
			get
			{
				if (bizPictureGroup == null)
					bizPictureGroup = new BizPictureGroup();
				return bizPictureGroup;
			}

		}

		//private BizVideoGroup 

		public BizBigEye() : base(dalBigEye) { }

		public BigEye Get(int targetEyeId, EnumSystemCategory targetType)
		{
			return dalBigEye.GetBy(eye => eye.TargetEyeID == targetEyeId && eye.TargetType == (int)targetType);
		}

		public void DeleteByGroupIDAndCategoryType(int targetEyeId, EnumSystemCategory targetType)
		{
			dalBigEye.DeleteBy(eye => eye.TargetEyeID == targetEyeId && eye.TargetType == (int)targetType);
		}

		public BigEye[] ListTop(EnumSystemCategory targetType, int count)
		{
			BigEye[] eyes = dalBigEye.ListBy<int>(eye => eye.TargetType == (int)targetType, eye => eye.OrderNo ?? 0, false).Take(count).ToArray();
			foreach (BigEye eye in eyes)
			{
				switch (targetType)
				{
					case EnumSystemCategory.图片:
						eye.PictureGroup = BizPictureGroup.Get(eye.TargetEyeID);
						if(eye.PictureGroup!=null)
							eye.PictureGroup.CoverImage = BizPicture.Get(eye.PictureGroup.CoverImageID ?? 0);
						//eye.PictureGroup.CoverImage.ThumbnailPath = Settings.Default.UploadFolder + eye.PictureGroup.CoverImage.ThumbnailPath;
						break;
					case EnumSystemCategory.音乐:
						//TODO 音乐
						throw new NotSupportedException();
						break;
					case EnumSystemCategory.视频:
						//TODO 视频
						throw new NotSupportedException();
						break;
					case EnumSystemCategory.新闻:
						//TODO 八卦
						throw new NotSupportedException();
						break;
				}
			}

			return eyes;
		}
	}
}
